<?php
namespace app\controller;

use app\BaseController;
use app\model\Banner;
use app\model\Note;

class Index extends BaseController
{
    public function index()
    {
        return $this->redirect('http://localhost:3000/');
    }

    public function bannerList()
    {
        $db = new Banner();
        $data = $db->hotBanner();
        $json=array('data'=>$data,'code'=>0,'tips'=>'ok');
        return json($json, 200);
    }

    public function hotNote()
    {
        $param = $this->request->param();
        $db = new Note();
        $data=  $db->hotPageList(['pageSize'=>$param['pageSize'],'pageNo'=>$param['pageNo']]);
        $json=array('data'=>$data,'code'=>0,'tips'=>'ok');
        return json($json, 200);
    }

    public function getAllNote()
    {
        $param = $this->request->param();
        $db = new Note();
        $data=  $db->pageFindAll2($param);
        $json=array('data'=>$data,'code'=>0,'tips'=>'ok');
        return json($json, 200);
    }

    public function findById($id)
    {
        $db = new Note();
        $data = $db->findById($id);
        if (!$data->isEmpty()) {
            $json=array('data'=>$data,'code'=>0,'tips'=>'ok');
        } else {
            $json=array('data'=>[],'code'=>2002,'tips'=>'没有查询到数据');
        }
        return json($json, 200);
    }

    public function getRandNote()
    {
        $db = new Note();
        $data = $db->randList();
        $json=array('data'=>$data,'code'=>0,'tips'=>'ok');
        return json($json, 200);
    }
}
